package com.qymerge.manage.core.utils.aliyun;//package com.doctor.core.utils.aliyun;
//
//import com.aliyun.api.AliyunClient;
//import com.aliyun.api.DefaultAliyunClient;
//import com.aliyun.api.cdn.cdn20141111.request.RefreshObjectCachesRequest;
//import com.aliyun.api.cdn.cdn20141111.response.RefreshObjectCachesResponse;
//import com.taobao.api.ApiException;
//import org.apache.log4j.Logger;
//import org.springframework.stereotype.Service;
//
///**
// * Desc CDN刷新服务
// * User qiuchen
// * Date 2015/5/8
// * Time 11:37
// */
//@Service
//public class RefreshCdnService {
//
//    static Logger logger = Logger.getLogger(RefreshCdnService.class.getName());
//
//    private static AliyunClient client = null;
//
//    static {
//        if (client == null) {
//            client = new DefaultAliyunClient(AliyunConfig.OSS.serverUrl, AliyunConfig.Amount.accessKeyId, AliyunConfig.Amount.accessKeySecret);
//        }
//    }
//
//    /**
//     * 刷新文件缓存
//     */
//    static public boolean refreshObjectCaches(String url) {
//        RefreshObjectCachesRequest request = new RefreshObjectCachesRequest();
//        request.setObjectType(ObjectType.File.name());
//        request.setObjectPath(url);
//        try {
//            RefreshObjectCachesResponse response = client.execute(request);
//            if (response.getErrorCode() == null || response.getErrorCode().length() == 0) {
//                return true;
//            }
//            //刷新失败
//            String errorCode = response.getErrorCode();//取得错误码
//            String message = response.getMessage();//取得错误信息
//            System.out.println(errorCode + "," + message);
//        } catch (ApiException e) {
//            logger.warn(e.getLocalizedMessage());
//            e.printStackTrace();
//            // TODO: handle exception
//        }
//        return false;
//    }
//
//    /**
//     * 刷新文件缓存
//     */
//    static public boolean refreshDirCaches(String dir) {
//        RefreshObjectCachesRequest request = new RefreshObjectCachesRequest();
//        request.setObjectType(ObjectType.Directory.name());
//        request.setObjectPath(dir);
//        try {
//            RefreshObjectCachesResponse response = client.execute(request);
//            if (response.getErrorCode() == null || response.getErrorCode().length() == 0) {
//                return true;
//            }
//            //刷新失败
//            String errorCode = response.getErrorCode();//取得错误码
//            String message = response.getMessage();//取得错误信息
//            System.out.println(errorCode + "," + message);
//        } catch (ApiException e) {
//            logger.warn(e.getLocalizedMessage());
//            e.printStackTrace();
//            // TODO: handle exception
//        }
//        return false;
//    }
//
//    /**
//     * 刷新路径类型
//     */
//    enum ObjectType {
//        File, Directory;
//    }
//
//    public static void main(String[] args) {
//        boolean ref = refreshDirCaches("http://m.one-dao.com/html/yidaozou/");
//        System.out.println(ref);
//    }
//
//}
//
//
